﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class TabControlPlusStyle6EffectForm : ItemFormTemplate
    {
        public TabControlPlusStyle6EffectForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
            this.Shown += new System.EventHandler(this.Form_Shown);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            view.ViewData = DemoHelper.GetDescription(AppDomain.CurrentDomain.BaseDirectory + "例子\\控件效果\\选项卡\\TabControlPlusStyle6EffectForm.rtf");
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {
            this.introduceBrowser.Rtf = viewObject.ViewData.ToString();
        }

        public override void ShowView()
        {
            base.ShowView();
        }

        public override void HideView()
        {
            base.HideView();
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            this.controlContainer.SizeChanged += this.ControlContainer_SizeChanged;

            this.demo_control.TabBar.Alignment = TabControlPlusTabBarAlignment.Left;
            this.demo_control.TabBar.Padding = new System.Windows.Forms.Padding(0, 6, 0, 6);
            this.demo_control.TabBar.TabItem.RoundQuality = false;
            this.demo_control.TabBar.TabItem.RoundSize = new RoundCorner(0);
            this.demo_control.TabBar.TabItem.Size = new System.Drawing.Size(160, 30);
            this.demo_control.StyleAppearance.TabBar.TabItem.Normal.BackColor = Color.FromArgb(130, 178, 178);
            this.demo_control.TabItemDrawBackgroundAfter += new HML.TabControlPlus.TabItemDrawBackgroundAfterEventHandler(this.Demo_control_TabItemDrawBackgroundAfter);

        }

        private void Form_Shown(object sender, EventArgs e)
        {
            this.splitContainer.SplitterDistance = Math.Max(this.splitContainer.Width / 4, this.splitContainer.Width - MainForm.GlobalSplitWidth);
            this.splitContainer.SplitterMoved += this.SplitContainer_SplitterMoved;

            MainForm.LoadAssistTabControl(this.assistTabControl);
        }

        private void SplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SplitContainer control = (SplitContainer)sender;
            MainForm.GlobalSplitWidth = this.splitContainer.Width - control.SplitterDistance;
        }

        private void ControlContainer_SizeChanged(object sender, EventArgs e)
        {
            Panel control = (Panel)sender;
            this.demo_control.Location = new Point((control.Width - this.demo_control.Width) / 2, (control.Height - this.demo_control.Height) / 2);
        }

        private void Demo_control_TabItemDrawBackgroundAfter(object sender, TabControlPlusTabItemDrawBackgroundAfterEventArgs e)
        {
            TabControlPlus tabControl = (TabControlPlus)e.TabPage.Parent;
            if (tabControl.TabPages[tabControl.SelectedIndex] == e.TabPage && e.TabPage != null)
            {
                int top = (int)(Math.Ceiling(tabControl.TabBar.Padding.Top * tabControl.ScaleDpi));
                int bottom = (int)(Math.Ceiling(tabControl.TabBar.Padding.Bottom * tabControl.ScaleDpi));
                int lr = (int)(Math.Ceiling(tabControl.TabBar.Padding.Top * tabControl.ScaleDpi));


                Region source_region = e.Graphics.Clip;
                RectangleF rect = new RectangleF(e.Bounds_P.X - top, e.Bounds_P.Y, e.Bounds_P.Width + top + bottom, e.Bounds_P.Height);
                Region tmp_region = new Region(rect);
                e.Graphics.Clip = tmp_region;

                SolidBrush line_sb = new SolidBrush(tabControl.StyleAppearance.TabBar.TabItem.Selected.BackColor);
                e.Graphics.FillRectangle(line_sb, new RectangleF(e.Bounds_P.X - top, e.Bounds_P.Y - lr, e.Bounds_P.Width + top + bottom, e.Bounds_P.Height + lr * 2));
                line_sb.Dispose();

                e.Graphics.Clip = tmp_region;
                tmp_region.Dispose();

            }
        }

        #endregion

    }
}
